namespace Vin.Tool.Core.RandomCategory;

public class RandomTool
{
    public static int RandomInt(int min, int max)
    {
        return new Random().Next(min, max);
    }

    public static double RandomDouble(double min, double max)
    {
        return new Random().NextDouble() * (max - min) + min;
    }

    public static long RandomLong(long min, long max)
    {
        return new Random().NextInt64(min, max);
    }

    public static string RandomString(char[] array, int length)
    {
        return new string(Enumerable.Repeat(array, length)
            .Select(s => s[new Random().Next(s.Length)]).ToArray());
    }

    public static string RandomString(int length)
    {
        const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
        return new string(Enumerable.Repeat(chars, length)
            .Select(s => s[new Random().Next(s.Length)]).ToArray());
    }

    public static string RandomLetter(int length, bool upperCase = true)
    {
        const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
        var randomString = new string(Enumerable.Repeat(chars, length)
            .Select(s => s[new Random().Next(s.Length)]).ToArray());
        return upperCase ? randomString.ToUpper() : randomString.ToLower();
    }

    public static string RandomNumber(int length)
    {
        const string chars = "0123456789";
        return new string(Enumerable.Repeat(chars, length)
            .Select(s => s[new Random().Next(s.Length)]).ToArray());
    }
}